<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改报告管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-report-edit" th:object="${report}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">摘要：</label>
                <div class="col-sm-8">
                    <input name="summary" th:field="*{summary}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">来源：</label>
                <div class="col-sm-8">
                    <input name="source" th:field="*{source}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">正文：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{content}">
                    <div class="summernote" id="content"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">发布时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="releaseTime" th:value="${#dates.format(report.releaseTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">原始链接：</label>
                <div class="col-sm-8">
                    <input name="sourceUrl" th:field="*{sourceUrl}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">预览链接：</label>
                <div class="col-sm-8">
                    <input name="previewUrl" th:field="*{previewUrl}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">所属行业：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('app_report_industry')}">
                    <label th:each="dict : ${type}" class="check-box">
                        <input name="industry" type="checkbox" th:value="${dict.dictValue}" th:text="${dict.dictLabel}" th:attr="checked=${report.industry.contains(dict.dictValue)?true:false}">
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">下载链接：</label>
                <div class="col-sm-8">
                    <input name="downloadUrl" th:field="*{downloadUrl}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">报告类型：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('app_report_type')}">
                    <label th:each="dict : ${type}" class="check-box">
                        <input name="type" type="checkbox" th:value="${dict.dictValue}" th:text="${dict.dictLabel}" th:attr="checked=${report.type.contains(dict.dictValue)?true:false}">
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">点数：</label>
                <div class="col-sm-8">
                    <input name="points" th:field="*{points}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">价格：</label>
                <div class="col-sm-8">
                    <input name="price" th:field="*{price}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上传时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="uploadTime" th:value="${#dates.format(report.uploadTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">存储路径：</label>
                <div class="col-sm-8">
                    <input name="storedFilePath" th:field="*{storedFilePath}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上传的文件名称：</label>
                <div class="col-sm-8">
                    <input name="uploadedFileName" th:field="*{uploadedFileName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">文件名称：</label>
                <div class="col-sm-8">
                    <input name="storedFileName" th:field="*{storedFileName}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript" src="/custom/js/upload.js" th:src="@{/custom/js/uploadReport.js}"></script>
    <script th:inline="javascript">
        var prefix = ctx + "module/report";
        $("#form-report-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-report-edit').serialize());
            }
        }

        $("input[name='releaseTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='uploadTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
</body>
</html>